<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\CreateNewDevelopmentTypeRequest;
use App\Http\Requests\UpdateNewDevelopmentTypeRequest;
use App\Repositories\NewDevelopmentTypeRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class NewDevelopmentTypeController extends AppBaseController
{
    /** @var  NewDevelopmentTypeRepository */
    private $newDevelopmentTypeRepository;

    public function __construct(NewDevelopmentTypeRepository $newDevelopmentTypeRepo)
    {
        $this->newDevelopmentTypeRepository = $newDevelopmentTypeRepo;
    }

    /**
     * Display a listing of the NewDevelopmentType.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->newDevelopmentTypeRepository->pushCriteria(new RequestCriteria($request));
        $newDevelopmentTypes = $this->newDevelopmentTypeRepository->all();

        return view('new_development_types.index')
            ->with('newDevelopmentTypes', $newDevelopmentTypes);
    }

    /**
     * Show the form for creating a new NewDevelopmentType.
     *
     * @return Response
     */
    public function create()
    {
        return view('new_development_types.create');
    }

    /**
     * Store a newly created NewDevelopmentType in storage.
     *
     * @param CreateNewDevelopmentTypeRequest $request
     *
     * @return Response
     */
    public function store(CreateNewDevelopmentTypeRequest $request)
    {
        $input = $request->all();

        $newDevelopmentType = $this->newDevelopmentTypeRepository->create($input);

        Flash::success('New Development Type saved successfully.');

        return redirect(route('newDevelopmentTypes.index'));
    }

    /**
     * Display the specified NewDevelopmentType.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $newDevelopmentType = $this->newDevelopmentTypeRepository->findWithoutFail($id);

        if (empty($newDevelopmentType)) {
            Flash::error('New Development Type not found');

            return redirect(route('newDevelopmentTypes.index'));
        }

        return view('new_development_types.show')->with('newDevelopmentType', $newDevelopmentType);
    }

    /**
     * Show the form for editing the specified NewDevelopmentType.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $newDevelopmentType = $this->newDevelopmentTypeRepository->findWithoutFail($id);

        if (empty($newDevelopmentType)) {
            Flash::error('New Development Type not found');

            return redirect(route('newDevelopmentTypes.index'));
        }

        return view('new_development_types.edit')->with('newDevelopmentType', $newDevelopmentType);
    }

    /**
     * Update the specified NewDevelopmentType in storage.
     *
     * @param  int              $id
     * @param UpdateNewDevelopmentTypeRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateNewDevelopmentTypeRequest $request)
    {
        $newDevelopmentType = $this->newDevelopmentTypeRepository->findWithoutFail($id);

        if (empty($newDevelopmentType)) {
            Flash::error('New Development Type not found');

            return redirect(route('newDevelopmentTypes.index'));
        }

        $newDevelopmentType = $this->newDevelopmentTypeRepository->update($request->all(), $id);

        Flash::success('New Development Type updated successfully.');

        return redirect(route('newDevelopmentTypes.index'));
    }

    /**
     * Remove the specified NewDevelopmentType from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $newDevelopmentType = $this->newDevelopmentTypeRepository->findWithoutFail($id);

        if (empty($newDevelopmentType)) {
            Flash::error('New Development Type not found');

            return redirect(route('newDevelopmentTypes.index'));
        }

        $this->newDevelopmentTypeRepository->delete($id);

        Flash::success('New Development Type deleted successfully.');

        return redirect(route('newDevelopmentTypes.index'));
    }
}
